package java2022_07_12;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class FileDemo12 {
    public static void main(String[] args) {
        //一旦按照OutputStream的方式打开文件，就会文件原来的内容给清空掉
        try(OutputStream outputStream = new FileOutputStream("./test.txt")){
            //写入一个字符
//            outputStream.write('a');
//            outputStream.write('b');
//            outputStream.write('c');
//            outputStream.write('d');
            //按照字节来写
//            byte[] buffer = new byte[]{
//                    (byte)'a',(byte)'b',(byte)'e',(byte)'f'
//            };
//            outputStream.write(buffer);
            String s = "hello world";
            outputStream.write(s.getBytes());
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}
